package com.ntschy.common.core.entity.dataobject;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ntschy.common.core.BaseEntity;
import com.ntschy.common.core.entity.enums.SysDataScopeEnum;
import com.ntschy.common.core.entity.enums.SysRoleMenuCheckStrictlyEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 角色表 sys_role
 * @author ezreal_geng
 */
@Data
@NoArgsConstructor  //无参构造函数
@TableName("SYS_ROLE")
@ApiModel(description = "角色实体类")
public class SysRole extends BaseEntity {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "角色ID")
    @TableId
    private String id;

    @ApiModelProperty(value = "角色名称")
    @TableField(value = "Name")
    private String name;

    @ApiModelProperty(value = "角色权限")
    @TableField(value = "RoleKey")
    private String roleKey;

    @ApiModelProperty(value = "角色排序")
    @TableField(value = "RoleSort")
    private Integer roleSort;

    @ApiModelProperty(value = "菜单树选择项是否关联显示（ 0：父子不互相关联显示 1：父子互相关联显示）")
    @TableField(value = "MenuCheckStrictly")
    private SysRoleMenuCheckStrictlyEnum menuCheckStrictly;

    @TableField(fill = FieldFill.INSERT, value = "CreateUserId")
    @ApiModelProperty(value = "创建人ID")
    private String createUserId;

    @TableField(fill = FieldFill.INSERT, value = "CreateTime")
    @ApiModelProperty(value = "创建时间")
    private String createTime;

    @TableField(exist = false)
    private boolean flag = false;

    @ApiModelProperty(value = "备注")
    @TableField(value = "Remark")
    private String remark;

    @ApiModelProperty(value = "菜单组")
    @TableField(exist = false)
    private String[] menuIds;

    @ApiModelProperty(value = "数据权限范围组（0：所有数据权限；1：自定义数据权限；2：本部门数据权限；3：本部门及以下数据权限）")
    @TableField(exist = false)
    private SysDataScopeEnum[] dataScopes;

    public boolean isAdmin() {
        return isAdmin(this.id);
    }

    public static boolean isAdmin(String roleId) {
        return StrUtil.isNotEmpty(roleId) && "1".equalsIgnoreCase(roleId);
    }

}
